using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data;
using DTO;
namespace DAO
{
   public  class PhieuTraSachDAO
    {
       public static DataTable LayDanhSachPhieuTraSach_DAO()
       {
           DataTable dt = new DataTable();
           string sql = "select * from PhieuTraSach";
           dt = DataProvider.ExcuteQuery(sql);
           return dt;
       }

       public static void ThemPhieuTraSach_DAO(PhieuTraSachDTO ptsDTO)
       {
           string sql = "insert into PhieuTraSach(MaPhieuMuonSach,NgayTra,TienPhat,TienNo,TongNo) values(";
           sql += ptsDTO.Maphieumuonsach.ToString() + ",'" + ptsDTO.Ngaytra + "'," + ptsDTO.Tienphat.ToString() + "," + ptsDTO.Tienno.ToString() + "," + ptsDTO.Tongno + ")";
           DataProvider.ExecutenonQuery(sql);
       }

       public static void CapNhatPhieuTraSach_DAO(PhieuTraSachDTO ptsDTO)
       {
           string sql = "update PhieuTraSach set MaPhieuMuonSach=" + ptsDTO.Maphieumuonsach.ToString() +",NgayTra='" + ptsDTO.Ngaytra.ToString() + "',TienPhat=" +ptsDTO.Tienphat.ToString();
           sql += ",TienNo=" + ptsDTO.Tienno.ToString() + ",TongNo=" +ptsDTO.Tongno.ToString()+" where MaPhieuTraSach="+ptsDTO.Maphieutrasach.ToString();
           DataProvider.ExecutenonQuery(sql);
       }

       public static void XoaPhieuTraSach_DAO(int maPhieuTraSach)
       {
           string sql = "delete from PhieuTraSach where MaPhieuTraSach=" + maPhieuTraSach.ToString();
           DataProvider.ExecutenonQuery(sql);
       }

       public static DataTable TimPhieuTraSach_DAO(DateTime ngayTra)
       {
           string sql = "select * from PhieuTraSach where DAY(NgayTra) =" + ngayTra.Day.ToString() + " and MONTH(NgayTra)=" + ngayTra.Month.ToString() + " and YEAR(NgayTra)=" + ngayTra.Year.ToString() ;
           DataTable dt = new DataTable();
           dt = DataProvider.ExcuteQuery(sql);
           return dt;
       }
    }
}
